###各國家計算腳本，繼承自西語通用計算類

import json
import os

from feature_set.app.un.app_un_comp_v1.AppUnCompV1 import AppUnCompV1


class AppIdCompV1(AppUnCompV1):
    def __init__(self, comp_list_type="more"):
        super().__init__()
        ###各國家的配置信息
        ###各國家app解析後對應的字段名
        self.country_info = json.load(
            open(
                os.path.join(
                    self.conf_dir,
                    "app",
                    "id",
                    "app_id_comp_v1",
                    "app_id_comp_v1_country_info.json",
                )
            )
        )
        ##配置竞品名单
        self.comp_set = set(
            [
                x.strip("\n")
                for x in open(
                    os.path.join(
                        self.conf_dir,
                        "app",
                        "id",
                        "app_id_comp_v1",
                        (
                            "comp_less.txt"
                            if comp_list_type == "less"
                            else "comp_more.txt"
                        ),
                    )
                )
            ]
        )
        self.app_name = "app_name"
        self.package_name = "app_package"
        self.inst_time_name = "fi_time"
        self.updt_time_name = "lu_time"
        self.pre_inst_name = "isSystem"

    def mark_pre_inst_tag(self):
        for app in self.app_list:
            if app["inst_time"] <= self.pre_inst_time_boundary:
                app["pre_inst_tag"] = 1
            else:
                app["pre_inst_tag"] = 0
